from fastapi import APIRouter, Depends
from app.core.responses import Response
from app.schemas.music import CreateMusic, List
from app.services.auth import get_current_user
from app.services.music import Music

router = APIRouter()


@router.get('/music')
def index(page: int = 0, pageSize: int = 10, user: str = Depends(get_current_user)):
    return Music.index(page, pageSize)


@router.get('/music/min_list')
def index(limit: int = 5, user: str = Depends(get_current_user)):
    return Music.min_list(limit)


@router.post('/music')
def store(form: CreateMusic, user: str = Depends(get_current_user)):
    if Music.create(form):
        return Response.message('操作成功')


@router.delete('/music/{id}')
def destroy(id: int, user: str = Depends(get_current_user)):
    if Music.delete(id):
        return Response.message('操作成功')


@router.post('/music/{id}')
def update(id: int, form: CreateMusic, user: str = Depends(get_current_user)):
    if Music.update(id, form):
        return Response.message('操作成功')


@router.get('/music_list')
def music_list_index(form: List, user: str = Depends(get_current_user)):
    return Music.index()


@router.post('/music_list')
def music_list_store(form: List, user: str = Depends(get_current_user)):
    if Music.list_store(form):
        return Response.message('操作成功')


@router.delete('/music_list/{id}')
def destroy(id: int, user: str = Depends(get_current_user)):
    if Music.list_delete(id):
        return Response.message('操作成功')


@router.post('/music_list/{id}')
def update(id: int, form: List, user: str = Depends(get_current_user)):
    if Music.list_update(id, form):
        return Response.message('操作成功')
